package com.foyekoo.project001.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.foyekoo.project001.activity.BackgroundActivity;

import com.foyekoo.project001.activity.PlayGameActivity;
import com.foyekoo.project001.activity.WaitingActivity;
import com.foyekoo.project001.config.LocalClient;
import com.foyekoo.project001.config.SpUtil;
import com.foyekoo.project001.utils.LogUtil;
import com.foyekoo.project001.utils.ReadThread;

/**
 * 全局监听数据
 */
public class DataBroadCastReceiver extends BroadcastReceiver {



    @Override
    public void onReceive(Context context, Intent intent) {
            byte[] array = intent.getByteArrayExtra(ReadThread.EXTRA_DATA);

            LogUtil.d("DataBroadCast","-->" + array[2] + ",-->" +array[3]);
            if (array == null) return;




            if (array[2] == 0x03){ //初始化发回给我的 用于保存
                LocalClient client = SpUtil.getInstance().getLocalClient();
                if(array[3] == 0x00) {
                    client.coinByOneGame = array[4];
                } else if (array[3] == 0x01){
                    client.gameTime = array[4];
                } else if (array[3] == 0x02){
                    client.saveStatus = array[4];
                } else if (array[3] == 0x03) {
                    client.autoCheckTime = array[4];
                } else if (array[3] == 0x04){
                    client.freeMode = array[4];
                } else if (array[3] == 0x05) {
                    client.strongPush_Z1 = array[4];
                    client.strongPush_Z2 = array[5];
                } else if (array[3] == 0x06) {
                    client.left_Right_Speed = array[4];
                    client.up_Down_Speed = array[5];
                } else if (array[3] == 0x07) {
                    client.power_Z1 = array[4];
                    client.power_Z2 = array[5];
                } else if (array[3] == 0x08) {
                    client.waitingTime_Z1 = array[4];
                    client.waitingTime_Z2 = array[5];
                } else if (array[3] == 0x09) {
                    client.alreadyCoin = array[4];
                }
                SpUtil.getInstance().saveCurrentClient(client);
            }
    }
}
